﻿<!DOCTYPE HTML>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="http://libs.useso.com/js/html5shiv/3.7/html5shiv.min.js"></script>
    <script type="text/javascript" src="http://libs.useso.com/js/respond.js/1.4.2/respond.min.js"></script>
    <script type="text/javascript" src="http://cdn.bootcss.com/css3pie/2.0beta1/PIE_IE678.js"></script>
    <![endif]-->
    <link href="../static/h-ui/css/H-ui.min.css" rel="stylesheet"
          type="text/css"/>
    <link href="../static/h-ui.admin/css/H-ui.login.css" rel="stylesheet"
          type="text/css"/>
    <link href="../static/h-ui.admin/css/style.css" rel="stylesheet"
          type="text/css"/>
    <link href="../static/lib/Hui-iconfont/1.0.8/iconfont.css"
          rel="stylesheet" type="text/css"/>
    <!--[if IE 7]>
    <link href="http://www.bootcss.com/p/font-awesome/assets/css/font-awesome-ie7.min.css" rel="stylesheet"
          type="text/css"/>
    <![endif]-->
    <title>修改密码</title>
</head>
<body>
<div class="pd-20">
    <form class="Huiform" id="chagne-password-form" action=""
          method="post">
        <table class="table table-border table-bordered table-bg"
               style="width: 500px; margin: auto;">
            <thead>
            <tr>
                <th colspan="2">修改密码</th>
            </tr>
            </thead>
            <tbody>
            <tr>
                <th class="text-r" width="30%">旧密码：</th>
                <td>
                    <div class="formControls">
                        <input name="oldpassword" id="oldpassword" class="input-text"
                               type="password" autocomplete="off" placeholder="密码"
                               tabindex="1">
                    </div>
                </td>
            </tr>
            <tr>
                <th class="text-r">新密码：</th>
                <td>
                    <div class="formControls">
                        <input name="newpassword" id="newpassword" class="input-text"
                               type="password" autocomplete="off" placeholder="设置密码"
                               tabindex="2">
                    </div>
                </td>
            </tr>
            <tr>
                <th class="text-r">再次输入新密码：</th>
                <td>
                    <div class="formControls">
                        <input name="newpassword2" id="newpassword2" class="input-text"
                               type="password" autocomplete="off" placeholder="确认新密码"
                               tabindex="3">
                    </div>
                </td>
            </tr>
            <tr>
                <th></th>
                <td>
                    <button type="submit" class="btn btn-success radius"
                            id="admin-password-save" name="admin-password-save">
                        <i class="icon-ok"></i> 确定
                    </button>
                </td>
            </tr>
            </tbody>
        </table>
    </form>
</div>

<div th:replace="_footer :: foot"></div>
<script type="text/javascript">
    $(function () {
        //表单验证
        $("#chagne-password-form").validate({
            rules: {
                oldpassword: {
                    required: true,
                },
                newpassword: {
                    required: true,
                },
                newpassword2: {
                    required: true,
                    equalTo: "#newpassword"
                }
            },
            messages: {
                oldpassword: {
                    required: "旧密码不能为空"
                },
                newpassword: {
                    required: "新密码不能为空"
                },
                newpassword2: {
                    required: "再次输入新密码",
                    equalTo: "两次密码输入不一致"
                }
            },

            onkeyup: false,
            focusCleanup: false,
            success: "valid",
            submitHandler: function () {
                ajaxSubmit();
            }

        });

        function ajaxSubmit() {
            $.ajax({
                type: 'POST',

                dataType: 'json',
                data: $('#chagne-password-form').serialize(),
                url: "saveNewPassword",
                success: function (data) {
                    if (data.success) {
                        window.location.href = "../";
                    } else {
                        alert(data.error);
                    }
                }
            });
            return false;
        }
    });
</script>
</body>
</html>